from django.db import models

from usermanage.models import UserInfo


class Author(models.Model):
    name = models.CharField(max_length=32)
    introduction = models.TextField(blank=True, null=True)
    book_count = models.IntegerField()
    age = models.IntegerField(blank=True, null=True)


class tag(models.Model):
    word = models.CharField(max_length=12)
    be_related = models.IntegerField()


class Books(models.Model):
    title = models.CharField(max_length=64)
    book_connect = models.CharField(max_length=128)
    pub_date = models.DateField(blank=True, null=True)
    # book_image = models.ImageField() # ???
    pub_name = models.CharField(max_length=64, blank=True, null=True)
    ISBN_Num = models.CharField(max_length=16, primary_key=True)
    be_collects = models.IntegerField()
    authors = models.ManyToManyField('Author')
    tags = models.ManyToManyField('tag')


class Book_Follow(models.Model):
    Follower = models.ForeignKey(UserInfo, related_name='Follow_UserInfo', on_delete=models.SET_NULL, blank=True,
                                 null=True,
                                 verbose_name='关注用户')

    Followed = models.ForeignKey(Books, related_name='Follow_Book', on_delete=models.SET_NULL, blank=True,
                                 null=True,
                                 verbose_name='被关注图书')
